package models

type User struct {
	Model

	//MetaNumber int `json:"meta_number" gorm:"index"`
	UserId   string `json:"user_id"        gorm:"type:varchar(100); not null; uniqueIndex"`
	Username string `json:"user_name"      gorm:"type:varchar(100); not null; uniqueIndex"`
	Password string `json:"password"       gorm:"type:varchar(100); not null"`
	//1: active
	Status int64 `json:"status"         gorm:"not null; default:1"`
	//0: common user
	Role int64 `json:"role"           gorm:"default:0"`
}

// AddCouponMeta add a single CouponMeta
func AddUsers(users []User) (int, error) {
	if err := db.Create(users).Error; err != nil {
		return 0, err
	}

	return len(users), nil
}

func VerifyCredentialInfo(username string, password string) bool {
	var user User

	err := db.Where("username = ?", username).First(&user).Error

	// Credential fail
	if err != nil {
		return false
	}

	if user.Username == username && user.Password == password {
		return true
	}

	return false
}
